<?php if (!defined('THINK_PATH')) exit(); /*a:3:{s:87:"D:\vue\xiangcun\ruoyi\webeditor\web/../source/application/admin\view\settings\basic.php";i:1760178330;s:85:"D:\vue\xiangcun\ruoyi\webeditor\source\application\admin\view\layout\layui_header.php";i:1760184068;s:85:"D:\vue\xiangcun\ruoyi\webeditor\source\application\admin\view\layout\layui_footer.php";i:1750747208;}*/ ?>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title><?php echo (isset($title) && ($title !== '')?$title:'精简版权限管理系统'); ?> - 管理后台</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <link href="/assets/common/css/layui.css" rel="stylesheet">
    <link rel="stylesheet" href="/assets/common/font-awesome.min.css">
    <style>
        /* 自定义样式补充 */
        .layui-logo {
            color: #fff;
            font-size: 18px;
            font-weight: bold;
        }
        
        .layui-nav-tree .layui-nav-item > a {
            height: 50px;
            line-height: 50px;
        }
        
        .layui-nav-tree .layui-nav-child dd a {
            height: 40px;
            line-height: 40px;
        }
        
        .layui-body {
            overflow-y: auto;
        }
        
        .main-content {
            padding: 20px;
            min-height: calc(100vh - 140px);
        }
        
        .page-header {
            margin-bottom: 20px;
            padding-bottom: 15px;
            border-bottom: 1px solid #f0f0f0;
        }
        
        .page-title {
            font-size: 24px;
            font-weight: 600;
            color: #333;
            margin: 0 0 8px 0;
        }
        
        .page-subtitle {
            color: #666;
            font-size: 14px;
            margin: 0;
        }
        
        .widget {
            background: #fff;
            border-radius: 8px;
            padding: 20px;
            margin-bottom: 20px;
            box-shadow: 0 2px 8px rgba(0,0,0,0.1);
        }
        
        .widget-header {
            display: flex;
            justify-content: space-between;
            align-items: center;
            margin-bottom: 20px;
            padding-bottom: 15px;
            border-bottom: 1px solid #f0f0f0;
        }
        
        .widget-title {
            font-size: 16px;
            font-weight: 600;
            color: #333;
            margin: 0;
        }
        
        .widget-actions {
            display: flex;
            gap: 10px;
        }
        
        .btn-widget {
            padding: 6px 12px;
            border: 1px solid #d9d9d9;
            border-radius: 4px;
            background: #fff;
            color: #666;
            text-decoration: none;
            font-size: 12px;
            transition: all 0.2s;
            cursor: pointer;
        }
        
        .btn-widget:hover {
            background: #1890ff;
            color: #fff;
            border-color: #1890ff;
        }
        
        /* 移动端适配 */
        @media (max-width: 768px) {
            .main-content {
                padding: 15px;
            }
            
            .widget {
                padding: 15px;
            }
            
            .widget-header {
                flex-direction: column;
                align-items: flex-start;
                gap: 10px;
            }
            
            .widget-actions {
                width: 100%;
            }
            
            .btn-widget {
                flex: 1;
                text-align: center;
            }
            
            /* 移动端左侧菜单默认隐藏 */
            .layui-side {
                left: -200px !important;
                transition: left 0.3s ease;
                z-index: 1001;
            }
            
            /* 移动端菜单展开状态 */
            .layui-layout-admin.mobile-menu-open .layui-side,
            .layui-side.mobile-menu-open {
                left: 0 !important;
            }
            
            /* 移动端内容区域调整 */
            .layui-body {
                left: 0 !important;
                transition: margin-left 0.3s ease;
            }
            
            /* 移动端遮罩层 */
            .mobile-menu-overlay {
                position: fixed;
                top: 0;
                left: 0;
                width: 100%;
                height: 100%;
                background: rgba(0, 0, 0, 0.5);
                z-index: 1000;
                display: none;
                opacity: 0;
                transition: opacity 0.3s ease;
            }
            
            .layui-layout-admin.mobile-menu-open .mobile-menu-overlay {
                display: block;
                opacity: 1;
            }
            
            /* 确保移动端菜单按钮可见 */
            .layui-nav .layui-nav-item[lay-header-event="menuLeft"] {
                display: inline-block !important;
            }
            
            /* 移动端菜单按钮样式 */
            .layui-nav .layui-nav-item[lay-header-event="menuLeft"] i {
                font-size: 18px;
                color: #fff;
            }
        }
        
        /* 移动端菜单按钮样式优化 */
        .layui-nav .layui-nav-item[lay-header-event="menuLeft"] {
            cursor: pointer;
        }
        
        .layui-nav .layui-nav-item[lay-header-event="menuLeft"]:hover {
            background-color: rgba(255, 255, 255, 0.1);
        }
    </style>
</head>
<body>
<script src="/assets/common/layui.js"></script>
<script>
    var $ = layui.jquery;
</script>
<div class="layui-layout layui-layout-admin">
    <!-- 头部区域 -->
    <div class="layui-header">
        <div class="layui-logo layui-hide-xs">精简版权限管理系统</div>
        <!-- 头部区域（可配合layui 已有的水平导航） -->
        <ul class="layui-nav layui-layout-left">
            <!-- 移动端显示 -->
            <li class="layui-nav-item layui-show-xs-inline-block layui-hide-sm" lay-header-event="menuLeft">
                <i class="layui-icon layui-icon-spread-left"></i>
            </li>
            <!-- 移动端标题 -->
            <li class="layui-nav-item layui-show-xs-inline-block layui-hide-sm" style="color: #fff; line-height: 60px; padding-left: 15px;">
                权限管理系统
            </li>
        </ul>
        <ul class="layui-nav layui-layout-right">
            <li class="layui-nav-item layui-hide layui-show-sm-inline-block">
                <a href="javascript:;">
                    <i class="layui-icon layui-icon-user"></i>
                    <?php
                    use think\Session;
                    $adminInfo = Session::get('admin_info');
                    echo $adminInfo ? $adminInfo['real_name'] ?: $adminInfo['username'] : '未知用户';
                    ?>
                </a>
                <dl class="layui-nav-child">
                    <dd><a href="<?php echo url('/admin/settings/profile'); ?>">个人信息</a></dd>
                    <dd><a href="<?php echo url('/admin/settings/basic'); ?>">系统设置</a></dd>
                    <dd><a href="<?php echo url('/admin/settings/changePassword'); ?>">修改密码</a></dd>
                    <dd><a href="javascript:;" id="logout-btn">退出登录</a></dd>
                </dl>
            </li>
        </ul>
    </div>
    
    <!-- 左侧导航区域 -->
    <div class="layui-side layui-bg-black">
        <div class="layui-side-scroll">
            <!-- 左侧导航区域（可配合layui已有的垂直导航） -->
            <ul class="layui-nav layui-nav-tree" lay-filter="nav">
                <?php
                use app\common\MenuHelper;
                echo MenuHelper::generateMenuHTML($current_page ?? '', $current_subpage ?? '');
                ?>
            </ul>
        </div>
    </div>
    

    
    <!-- 移动端菜单遮罩层 -->
    <div class="mobile-menu-overlay"></div>
    
    <script src="/assets/common/js/layui.js"></script>
    <script>
    // 退出登录功能
    layui.use(['layer', 'jquery'], function(){
        var layer = layui.layer;
        var $ = layui.jquery;
        
        // 退出登录
        $(document).on('click', '#logout-btn', function(e){
            e.preventDefault();
            layer.confirm('确定要退出登录吗？', {
                icon: 3,
                title: '提示'
            }, function(index){
                $.ajax({
                    url: '/admin/login/logout',
                    type: 'POST',
                    dataType: 'json',
                    success: function(res) {
                        layer.close(index);
                        if (res.code === 0) {
                            layer.msg(res.msg || '退出成功', {icon: 1, time: 1000}, function(){
                                window.location.href = res.redirect || '/admin/login';
                            });
                        } else {
                            layer.msg(res.msg || '退出失败', {icon: 2});
                        }
                    },
                    error: function() {
                        layer.close(index);
                        layer.msg('网络错误，请稍后重试', {icon: 2});
                    }
                });
            });
            return false;
        });
    });
    </script>
    
    <!-- 内容主体区域 -->
    <div class="layui-body">

<!-- 主要内容 -->
<div class="main-content">
    <div class="page-header">
        <h1 class="page-title">基础设置</h1>
        <p class="page-subtitle">配置系统的基本参数和信息</p>
    </div>

    <!-- 设置选项卡 -->
    <div class="layui-card">
        <div class="layui-card-body">
            <div class="layui-tab layui-tab-brief" lay-filter="settingsTab">
                <ul class="layui-tab-title">
                    <li class="layui-this">
                        <i class="fas fa-info-circle"></i> 系统信息
                    </li>
                    <li>
                        <i class="fas fa-bell"></i> 通知设置
                    </li>
                </ul>
                
                <div class="layui-tab-content">
                    <!-- 系统信息 -->
                    <div class="layui-tab-item layui-show">
                        <form class="layui-form" lay-filter="systemInfoForm">
                            <div class="layui-row layui-col-space20">
                                <div class="layui-col-md6">
                                    <div class="layui-form-item">
                                        <label class="layui-form-label">系统名称</label>
                                        <div class="layui-input-block">
                                            <input type="text" name="system_name" value="大头停车管理系统" class="layui-input">
                                        </div>
                                    </div>
                                    <div class="layui-form-item">
                                        <label class="layui-form-label">企业名称</label>
                                        <div class="layui-input-block">
                                            <input type="text" name="company_name" value="智慧科技有限公司" class="layui-input">
                                        </div>
                                    </div>
                                    <div class="layui-form-item">
                                        <label class="layui-form-label">企业地址</label>
                                        <div class="layui-input-block">
                                            <input type="text" name="company_address" value="深圳市南山区科技园" class="layui-input">
                                        </div>
                                    </div>
                                    <div class="layui-form-item">
                                        <label class="layui-form-label">联系电话</label>
                                        <div class="layui-input-block">
                                            <input type="text" name="contact_phone" value="400-123-4567" class="layui-input">
                                        </div>
                                    </div>
                                </div>
                                <div class="layui-col-md6">
                                    <div class="layui-form-item">
                                        <label class="layui-form-label">系统版本</label>
                                        <div class="layui-input-block">
                                            <input type="text" name="version" value="v2.1.0" readonly class="layui-input">
                                        </div>
                                    </div>
                                    <div class="layui-form-item">
                                        <label class="layui-form-label">运营商</label>
                                        <div class="layui-input-block">
                                            <input type="text" name="operator" value="智慧科技有限公司" class="layui-input">
                                        </div>
                                    </div>
                                    <div class="layui-form-item">
                                        <label class="layui-form-label">客服邮箱</label>
                                        <div class="layui-input-block">
                                            <input type="email" name="service_email" value="service@park.com" class="layui-input">
                                        </div>
                                    </div>
                                    <div class="layui-form-item">
                                        <label class="layui-form-label">官网地址</label>
                                        <div class="layui-input-block">
                                            <input type="url" name="website" value="https://www.park.com" class="layui-input">
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <div class="layui-input-block">
                                    <button type="submit" class="layui-btn" lay-submit lay-filter="saveSystemInfo">保存设置</button>
                                    <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                                </div>
                            </div>
                        </form>
                    </div>

                    <!-- 通知设置 -->
                    <div class="layui-tab-item">
                        <form class="layui-form" lay-filter="notificationForm">
                            <div class="layui-row layui-col-space20">
                                <div class="layui-col-md6">
                                    <div class="layui-card">
                                        <div class="layui-card-header">短信通知</div>
                                        <div class="layui-card-body">
                                            <div class="layui-form-item">
                                                <label class="layui-form-label">启用短信</label>
                                                <div class="layui-input-block">
                                                    <input type="checkbox" name="sms_enable" lay-skin="switch" lay-text="开启|关闭" checked>
                                                </div>
                                            </div>
                                            <div class="layui-form-item">
                                                <label class="layui-form-label">短信服务商</label>
                                                <div class="layui-input-block">
                                                    <select name="sms_provider" lay-filter="smsProvider">
                                                        <option value="smsbao" selected>短信宝</option>
                                                        <option value="aliyun">阿里云</option>
                                                        <option value="tencent">腾讯云</option>
                                                        <option value="baidu">百度云</option>
                                                    </select>
                                                </div>
                                            </div>
                                            
                                            <!-- 短信宝配置 -->
                                            <div id="smsbaoConfig">
                                                <div class="layui-form-item">
                                                    <label class="layui-form-label">短信宝用户名</label>
                                                    <div class="layui-input-block">
                                                        <input type="text" name="smsbao_username" placeholder="请输入短信宝用户名" class="layui-input">
                                                        <div class="layui-form-mid layui-word-aux">在短信宝官网注册的用户名</div>
                                                    </div>
                                                </div>
                                                <div class="layui-form-item">
                                                    <label class="layui-form-label">短信宝密码/ApiKey</label>
                                                    <div class="layui-input-block">
                                                        <input type="password" name="smsbao_password" placeholder="请输入密码MD5值或ApiKey" class="layui-input">
                                                        <div class="layui-form-mid layui-word-aux">建议使用ApiKey，更安全</div>
                                                    </div>
                                                </div>
                                                <div class="layui-form-item">
                                                    <label class="layui-form-label">短信签名</label>
                                                    <div class="layui-input-block">
                                                        <input type="text" name="smsbao_signature" value="【智慧企业】" placeholder="请输入短信签名" class="layui-input">
                                                        <div class="layui-form-mid layui-word-aux">格式：【签名内容】，需在短信宝后台报备审核</div>
                                                    </div>
                                                </div>
                                                <div class="layui-form-item">
                                                    <label class="layui-form-label">测试手机号</label>
                                                    <div class="layui-input-block">
                                                        <input type="text" name="smsbao_test_phone" placeholder="可选，用于测试短信发送" class="layui-input">
                                                        <div class="layui-form-mid layui-word-aux">填写后可点击测试按钮发送测试短信</div>
                                                    </div>
                                                </div>
                                                <div class="layui-form-item">
                                                    <div class="layui-input-block">
                                                        <button type="button" class="layui-btn layui-btn-normal" id="testSmsBtn">
                                                            <i class="layui-icon layui-icon-cellphone"></i> 发送测试短信
                                                        </button>
                                                        <button type="button" class="layui-btn layui-btn-primary" id="checkBalanceBtn">
                                                            <i class="layui-icon layui-icon-rmb"></i> 查询余额
                                                        </button>
                                                    </div>
                                                </div>
                                            </div>

                                            <!-- 其他服务商配置（隐藏） -->
                                            <div id="cloudSmsConfig" style="display: none;">
                                                <div class="layui-form-item">
                                                    <label class="layui-form-label">AccessKey</label>
                                                    <div class="layui-input-block">
                                                        <input type="text" name="sms_access_key" placeholder="请输入AccessKey" class="layui-input">
                                                    </div>
                                                </div>
                                                <div class="layui-form-item">
                                                    <label class="layui-form-label">SecretKey</label>
                                                    <div class="layui-input-block">
                                                        <input type="password" name="sms_secret_key" placeholder="请输入SecretKey" class="layui-input">
                                                    </div>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                                <div class="layui-col-md6">
                                    <div class="layui-card">
                                        <div class="layui-card-header">邮件通知</div>
                                        <div class="layui-card-body">
                                            <div class="layui-form-item">
                                                <label class="layui-form-label">启用邮件</label>
                                                <div class="layui-input-block">
                                                    <input type="checkbox" name="email_enable" lay-skin="switch" lay-text="开启|关闭">
                                                </div>
                                            </div>
                                            <div class="layui-form-item">
                                                <label class="layui-form-label">SMTP服务器</label>
                                                <div class="layui-input-block">
                                                    <input type="text" name="smtp_host" placeholder="smtp.example.com" class="layui-input">
                                                </div>
                                            </div>
                                            <div class="layui-form-item">
                                                <label class="layui-form-label">端口</label>
                                                <div class="layui-input-block">
                                                    <input type="number" name="smtp_port" value="587" class="layui-input">
                                                </div>
                                            </div>
                                            <div class="layui-form-item">
                                                <label class="layui-form-label">发件邮箱</label>
                                                <div class="layui-input-block">
                                                    <input type="email" name="email_username" placeholder="sender@example.com" class="layui-input">
                                                </div>
                                            </div>
                                            <div class="layui-form-item">
                                                <label class="layui-form-label">邮箱密码</label>
                                                <div class="layui-input-block">
                                                    <input type="password" name="email_password" placeholder="请输入邮箱密码" class="layui-input">
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>

                            <div class="layui-form-item">
                                <div class="layui-input-block">
                                    <button type="submit" class="layui-btn" lay-submit lay-filter="saveNotificationConfig">保存配置</button>
                                    <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                                </div>
                            </div>
                        </form>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<script>
layui.use(['form', 'layer', 'element'], function(){
    var form = layui.form;
    var layer = layui.layer;
    var element = layui.element;
    
    // 监听系统信息表单提交
    form.on('submit(saveSystemInfo)', function(data){
        layer.msg('正在保存系统信息...', {icon: 16});
        
        // 发送AJAX请求保存数据
        $.ajax({
            url: '/admin/settings/saveSystemInfo',
            method: 'POST',
            data: data.field,
            success: function(res) {
                if(res.code === 200) {
                    layer.msg('系统信息保存成功', {icon: 1});
                } else {
                    layer.msg(res.message || '保存失败', {icon: 2});
                }
            },
            error: function() {
                layer.msg('网络错误，保存失败', {icon: 2});
            }
        });
        
        return false;
    });
    
    // 监听通知设置表单提交
    form.on('submit(saveNotificationConfig)', function(data){
        layer.msg('正在保存通知设置...', {icon: 16});
        
        // 发送AJAX请求保存短信宝配置
        $.ajax({
            url: '/admin/settings/saveNotificationConfig',
            method: 'POST',
            data: data.field,
            success: function(res) {
                if(res.code === 200) {
                    layer.msg('通知设置保存成功', {icon: 1});
                } else {
                    layer.msg(res.message || '保存失败', {icon: 2});
                }
            },
            error: function() {
                layer.msg('网络错误，保存失败', {icon: 2});
            }
        });
        
        return false;
    });

    // 监听短信服务商切换
    form.on('select(smsProvider)', function(data){
        var provider = data.value;
        if(provider === 'smsbao') {
            $('#smsbaoConfig').show();
            $('#cloudSmsConfig').hide();
        } else {
            $('#smsbaoConfig').hide();
            $('#cloudSmsConfig').show();
        }
    });

    // 测试短信发送
    $('#testSmsBtn').click(function() {
        var username = $('input[name="smsbao_username"]').val();
        var password = $('input[name="smsbao_password"]').val();
        var signature = $('input[name="smsbao_signature"]').val();
        var testPhone = $('input[name="smsbao_test_phone"]').val();

        if(!username || !password || !signature || !testPhone) {
            layer.msg('请先完善短信宝配置信息和测试手机号', {icon: 2});
            return;
        }

        // 验证手机号格式
        if(!/^1[3-9]\d{9}$/.test(testPhone)) {
            layer.msg('请输入正确的手机号格式', {icon: 2});
            return;
        }

        layer.confirm('确定要发送测试短信吗？', {icon: 3, title:'测试确认'}, function(index){
            layer.close(index);
            layer.load(1);

            $.ajax({
                url: '/api/sms/sendTest',
                method: 'POST',
                data: {
                    username: username,
                    password: password,
                    signature: signature,
                    phone: testPhone,
                    content: '这是一条测试短信，短信宝配置正常。'
                },
                success: function(res) {
                    layer.closeAll('loading');
                    if(res.code === 200) {
                        layer.msg('测试短信发送成功！', {icon: 1, time: 3000});
                    } else {
                        layer.msg('测试失败：' + (res.message || '未知错误'), {icon: 2, time: 5000});
                    }
                },
                error: function() {
                    layer.closeAll('loading');
                    layer.msg('网络错误，测试失败', {icon: 2});
                }
            });
        });
    });

    // 查询余额
    $('#checkBalanceBtn').click(function() {
        var username = $('input[name="smsbao_username"]').val();
        var password = $('input[name="smsbao_password"]').val();

        if(!username || !password) {
            layer.msg('请先配置短信宝用户名和密码', {icon: 2});
            return;
        }

        layer.load(1);

        $.ajax({
            url: '/api/sms/balance',
            method: 'POST',
            data: {
                username: username,
                password: password
            },
            success: function(res) {
                layer.closeAll('loading');
                if(res.code === 200) {
                    var data = res.data;
                    layer.open({
                        type: 1,
                        title: '短信宝账户余额',
                        content: `
                            <div style="padding: 20px;">
                                <p style="margin: 10px 0; font-size: 16px;">
                                    <i class="layui-icon layui-icon-rmb" style="color: #01AAED;"></i> 
                                    已发送：<strong style="color: #FF5722;">${data.sent_count || 0}</strong> 条
                                </p>
                                <p style="margin: 10px 0; font-size: 16px;">
                                    <i class="layui-icon layui-icon-ok" style="color: #01AAED;"></i> 
                                    剩余：<strong style="color: #009688;">${data.remaining_count || 0}</strong> 条
                                </p>
                                <p style="margin: 10px 0; font-size: 14px; color: #999;">
                                    查询时间：${data.query_time || new Date().toLocaleString()}
                                </p>
                            </div>
                        `,
                        area: ['350px', '200px'],
                        btn: ['确定'],
                        btnAlign: 'c'
                    });
                } else {
                    layer.msg('查询失败：' + (res.message || '未知错误'), {icon: 2, time: 5000});
                }
            },
            error: function() {
                layer.closeAll('loading');
                layer.msg('网络错误，查询失败', {icon: 2});
            }
        });
    });
    
    console.log('基础设置页面加载完成');
});
</script>

</div>
    
    <!-- 底部固定区域 -->
    <div class="layui-footer">
        © 2025 大头停车管理系统 - 智能停车解决方案
    </div>
</div>

<!-- <script src="/assets/common/layui.js"></script> -->
<script>
//JS 
layui.use(['element', 'layer', 'util'], function(){
    var element = layui.element;
    var layer = layui.layer;
    var util = layui.util;
    
    // 重新渲染元素，确保菜单正常工作
    element.render('nav');
    
    //头部事件
    util.event('lay-header-event', {
        menuLeft: function(othis){ // 左侧菜单事件 - 移动端菜单切换
            toggleMobileMenu();
        },
        menuRight: function(){  // 右侧菜单事件
            layer.open({
                type: 1,
                title: '更多',
                content: '<div style="padding: 15px;">处理右侧面板的操作</div>',
                area: ['260px', '100%'],
                offset: 'rt', // 右上角
                anim: 'slideLeft', // 从右侧抽屉滑出
                shadeClose: true,
                scrollbar: false
            });
        }
    });
    
    // 移动端菜单控制函数
    function toggleMobileMenu() {
        var $layout = $('.layui-layout-admin');
        var $side = $('.layui-side');
        var $overlay = $('.mobile-menu-overlay');
        
        console.log('toggleMobileMenu 被调用');
        
        if ($layout.hasClass('mobile-menu-open')) {
            // 关闭菜单
            $layout.removeClass('mobile-menu-open');
            $side.removeClass('mobile-menu-open');
            console.log('关闭移动端菜单');
        } else {
            // 打开菜单
            $layout.addClass('mobile-menu-open');
            $side.addClass('mobile-menu-open');
            console.log('打开移动端菜单');
        }
    }
    
    // 点击遮罩层关闭菜单
    $(document).on('click', '.mobile-menu-overlay', function() {
        console.log('点击遮罩层关闭菜单');
        $('.layui-layout-admin').removeClass('mobile-menu-open');
        $('.layui-side').removeClass('mobile-menu-open');
    });
    
    // 监听窗口大小变化，当屏幕变大时自动关闭移动端菜单
    $(window).on('resize', function() {
        if ($(window).width() > 768) {
            console.log('屏幕变大，关闭移动端菜单');
            $('.layui-layout-admin').removeClass('mobile-menu-open');
            $('.layui-side').removeClass('mobile-menu-open');
        }
    });
    
    // 添加移动端菜单项点击后自动关闭菜单的功能
    $(document).on('click', '.layui-side .layui-nav a', function(e) {
        if ($(window).width() <= 768) {
            var href = $(this).attr('href');
            if (href && href !== 'javascript:;' && href.indexOf('#') !== 0) {
                setTimeout(function() {
                    $('.layui-layout-admin').removeClass('mobile-menu-open');
                    $('.layui-side').removeClass('mobile-menu-open');
                }, 200);
            }
        }
    });
    
    // 设置当前页面导航高亮
    var currentPath = window.location.pathname;
    var currentUrl = window.location.href;
    
    // 获取当前页面的控制器和方法
    var urlParams = new URLSearchParams(window.location.search);
    var currentController = '';
    var currentAction = '';
    
    // 解析URL参数中的s参数（如：/admin/park）
    if (urlParams.get('s')) {
        var sParam = urlParams.get('s');
        var parts = sParam.split('/');
        if (parts.length >= 3) {
            currentController = parts[2]; // admin后面的控制器名
            currentAction = parts[3] || 'index'; // 方法名，默认index
        }
    } else {
        // 如果没有s参数，从路径中解析
        var pathParts = currentPath.split('/');
        if (pathParts.length >= 3) {
            currentController = pathParts[2];
            currentAction = pathParts[3] || 'index';
        }
    }
    
    console.log('当前控制器:', currentController, '当前方法:', currentAction);
    
    // 遍历所有菜单项进行匹配
    $('.layui-nav-tree a').each(function(){
        var $this = $(this);
        var href = $this.attr('href');
        var isMatched = false;
        
        if (href && href !== 'javascript:;') {
            // 处理完整URL匹配
            if (href.indexOf('http') === 0) {
                if (currentUrl === href) {
                    isMatched = true;
                }
            } else {
                // 处理相对路径匹配
                if (href.indexOf('?s=') !== -1) {
                    // 解析href中的s参数
                    var hrefUrl = new URL(href, window.location.origin);
                    var hrefS = hrefUrl.searchParams.get('s');
                    if (hrefS) {
                        var hrefParts = hrefS.split('/');
                        if (hrefParts.length >= 3) {
                            var hrefController = hrefParts[2];
                            var hrefAction = hrefParts[3] || 'index';
                            
                            // 精确匹配控制器
                            if (currentController === hrefController) {
                                // 如果是同一个控制器，进一步检查方法
                                if (hrefAction === 'index' || currentAction === hrefAction) {
                                    isMatched = true;
                                }
                            }
                        }
                    }
                } else {
                    // 传统路径匹配
                    if (currentPath.indexOf(href) === 0) {
                        isMatched = true;
                    }
                }
            }
        }
        
        if (isMatched) {
            $this.parent().addClass('layui-this');
            $this.parents('.layui-nav-item').addClass('layui-nav-itemed');
            console.log('匹配到菜单:', href);
        }
    });
    
    // 监听导航点击事件，确保菜单正常工作
    element.on('nav(nav)', function(elem){
        // 菜单点击事件处理
        console.log('菜单点击：', elem);
    });
    
    // 确保所有有子菜单的项目都能正常展开
    $('.layui-nav-tree .layui-nav-item').each(function(){
        var $this = $(this);
        if($this.find('.layui-nav-child').length > 0){
            $this.find('> a').off('click').on('click', function(e){
                e.preventDefault();
                
                // 切换展开状态
                if($this.hasClass('layui-nav-itemed')){
                    $this.removeClass('layui-nav-itemed');
                } else {
                    $this.addClass('layui-nav-itemed');
                }
                
                return false;
            });
        }
    });
});
</script>
</body>
</html> 